<template>
<div>
  <div align="left">我的位置&gt;&gt;科技项目申报&gt;申请项目信息</div>
  <div id="container">
    <div id="content2">
      <table width="100%" height="21" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td width="15" height="15" align="left" valign="top">
            <div align="left"></div>
          </td>
          <td width="385" align="left" valign="bottom" class="12">&nbsp;</td>
        </tr>
        <tr>
          <td height="15" align="left" valign="top">&nbsp;</td>
          <td height="15" align="left" valign="top" class="12">
            <table width="100%" height="15" border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td height="20" align="center">
                  <div class="right_proaducts">
                  </div>
                  <div class=padding>
                    <div id=middlebody>
                      <table width="60%" border="0" cellpadding="0" cellspacing="1">
                        <input type="hidden" value="4" name="categoryid"/>
                        <input type="hidden" value="5" name="unitid"/>
                        <tbody>
                        <tr>
                          <td width="126" align="right" bgcolor="#f3f3f3">项目分类名称</td>
                          <td width="10" align="right" bgcolor="#f3f3f3">&nbsp;</td>
                          <td colspan="2" bgcolor="#f3f3f3">
                            <div align="left">{{projectInfo.projectCategoryName}}</div>
                          </td>
                        </tr>
                        <tr>
                          <td align="right" bgcolor="#f3f3f3">项目名称</td>
                          <td align="right" bgcolor="#f3f3f3">&nbsp;</td>
                          <td colspan="2" bgcolor="#f3f3f3">
                            <div align="left">
                              <input v-model="projectInfo.projectName" ref="projectName"
                                     name="projectname"/>
                            </div>
                          </td>
                        </tr>
                        <tr>
                          <td align="right" bgcolor="#f3f3f3">申请单位</td>
                          <td align="right" bgcolor="#f3f3f3">&nbsp;</td>
                          <td colspan="2" bgcolor="#f3f3f3">
                            <div align="left">
                              <input v-model="projectInfo.unitName" readonly="readonly"
                                     name="unitname2"/>
                            </div>
                          </td>
                        </tr>
                        <tr>
                          <td align="right" bgcolor="#f3f3f3">申请人</td>
                          <td align="right" bgcolor="#f3f3f3">&nbsp;</td>
                          <td colspan="2" bgcolor="#f3f3f3">
                            <div align="left">
                              <input v-model="projectInfo.applicant" ref="applicant"
                                     name="applicant"/>
                            </div>
                          </td>
                        </tr>
                        <tr>
                          <td align="right" bgcolor="#f3f3f3">职称</td>
                          <td align="right" bgcolor="#f3f3f3">&nbsp;</td>
                          <td colspan="2" bgcolor="#f3f3f3">
                            <div align="left">
                              <input v-model="projectInfo.grade" ref="grade" name="grade"/>
                            </div>
                          </td>
                        </tr>
                        <tr>
                          <td align="right" bgcolor="#f3f3f3">学历</td>
                          <td align="right" bgcolor="#f3f3f3">&nbsp;</td>
                          <td colspan="2" bgcolor="#f3f3f3">
                            <div align="left">
                              <input v-model="projectInfo.education" ref="education"
                                     name="education"/>
                            </div>
                          </td>
                        </tr>
                        <tr>
                          <td align="right" bgcolor="#f3f3f3">申请时间</td>
                          <td align="right" bgcolor="#f3f3f3">&nbsp;</td>
                          <td colspan="2" bgcolor="#f3f3f3">
                            <div align="left">
                              <input v-model="projectInfo.fillDate" readonly="readonly"
                                     name="fillDate"/>
                            </div>
                          </td>
                        </tr>
                        <tr>
                          <td align="right" bgcolor="#f3f3f3">项目现状</td>
                          <td align="right" bgcolor="#f3f3f3">&nbsp;</td>
                          <td colspan="2" bgcolor="#f3f3f3">
                            <div align="left">
                              <input v-model="projectInfo.status" ref="status" name="status"/>
                            </div>
                          </td>
                        </tr>
                        <tr>
                          <td align="right" bgcolor="#f3f3f3">项目前景</td>
                          <td align="right" bgcolor="#f3f3f3">&nbsp;</td>
                          <td colspan="2" bgcolor="#f3f3f3">
                            <div align="left">
                              <input v-model="projectInfo.future" ref="future" name="future"/>
                            </div>
                          </td>
                        </tr>
                        <tr>
                          <td align="right" bgcolor="#f3f3f3">重难点分析</td>
                          <td align="right" bgcolor="#f3f3f3">&nbsp;</td>
                          <td colspan="2" bgcolor="#f3f3f3">
                            <div align="left">
                              <input v-model="projectInfo.analysis" ref="analysis"
                                     name="analysis"/>
                            </div>
                          </td>
                        </tr>
                        <tr>
                          <td align="right" bgcolor="#f3f3f3">研究方法</td>
                          <td align="right" bgcolor="#f3f3f3">&nbsp;</td>
                          <td colspan="2" bgcolor="#f3f3f3">
                            <div align="left">
                              <input v-model="projectInfo.way" ref="way" name="way"/>
                            </div>
                          </td>
                        </tr>
                        <tr>
                          <td align="right" bgcolor="#f3f3f3">预计研究成果</td>
                          <td align="right" bgcolor="#f3f3f3">&nbsp;</td>
                          <td colspan="2" bgcolor="#f3f3f3">
                            <div align="left">
                              <input v-model="projectInfo.result" ref="result" name="result"/>
                            </div>
                          </td>
                        </tr>
                        <tr>
                          <td align="right" bgcolor="#f3f3f3">申请资金</td>
                          <td align="right" bgcolor="#f3f3f3">&nbsp;</td>
                          <td colspan="2" bgcolor="#f3f3f3">
                            <div align="left">
                              <input v-model="projectInfo.capital" ref="capital"
                                     name="capital"/>
                            </div>
                          </td>
                        </tr>
                        <tr>
                          <td colspan="2" align="right" bgcolor="#f3f3f3">&nbsp;</td>
                          <td width="70" bgcolor="#f3f3f3">
                            <div align="left">
                              <input type="button" @click="applyProject()" value="申请"/>
                            </div>
                          </td>
                          <td width="239" bgcolor="#f3f3f3">
                            <div align="left">
                              <input type="reset" @click="resetProjectInfo()" value="重置"/>
                            </div>
                          </td>
                        </tr>
                        </tbody>
                      </table>
                    </div>
                  </div>
                </td>
              </tr>
            </table>
            <br/>
            <div class="table_wz"></div>
          </td>
        </tr>
      </table>
    </div>
  </div>
  <div id="container">
    <div id="footer">
      <p><a href="http://www.ascenttech.com.cn/" target="_blank">版权所有：北京亚思晟商务科技有限公司 &copy;2004-2008|京ICP备05005681</a>
      </p>
    </div>

  </div>
</div>
</template>

<script>
export default {
  name: "applyProject",
  data() {
    return {
      uid: JSON.parse(sessionStorage.getItem("userInfo")).uid || "",
      projectInfo: {
        projectCategoryName: '',
        categoryid: '',
        unitid: JSON.parse(sessionStorage.getItem("userInfo")).unitid || '',
        projectName: '',
        unitName: JSON.parse(sessionStorage.getItem("userInfo")).unitname || '',
        fillDate: '',
        applicant: '',
        grade: '',
        education: '',
        status: '',
        future: '',
        analysis: '',
        way: '',
        result: '',
        capital: ''
      },
    }
  },
  mounted() {
    this.getCid();
    this.selectProject();
  },
  methods: {
    //注销
    logout() {
      sessionStorage.clear();
    },
    //获取项目projectId
    getCid() {
      var strings = window.location.href.split('?')[1];
      let getCid = new URLSearchParams('?' + strings)  //将参数放在URLSearchParams函数中
      let cid = getCid.get('cid');
      // console.log(cid);
      return cid;
    },
    //获取项目信息
    selectProject() {
      var _this = this;
      this.$axios({
        url: `http://localhost:8080/api/unit/select/category/${_this.getCid()}`,
        method: 'get',
      }).then((res) => {
        // console.log(res);
        // console.log(res.data.data);
        if (res.data.code == 200) {
          _this.projectInfo.projectCategoryName = res.data.data.categories.categoryname;
          _this.projectInfo.fillDate = res.data.data.categories.repStartTime;
        }
      })
    },
    applyProject() {         //申请项目
      if (this.projectInfo.projectName == "") {
        alert("项目名称不能为空");
        this.$refs['projectName'].focus();
      } else if (this.projectInfo.applicant == "") {
        alert("申请人不能为空");
        this.$refs['applicant'].focus();
      } else if (this.projectInfo.grade == "") {
        alert("职称不能为空");
        this.$refs['grade'].focus();
      } else if (this.projectInfo.education == "") {
        alert("学历不能为空");
        this.$refs['education'].focus();
      } else if (this.projectInfo.status == "") {
        alert("项目现状不能为空");
        this.$refs['status'].focus();
      } else if (this.projectInfo.future == "") {
        alert("项目前景不能为空");
        this.$refs['future'].focus();
      } else if (this.projectInfo.analysis == "") {
        alert("重难点分析不能为空");
        this.$refs['analysis'].focus();
      } else if (this.projectInfo.way == "") {
        alert("研究方法不能为空");
        this.$refs['way'].focus();
      } else if (this.projectInfo.result == "") {
        alert("预计研究成果不能为空");
        this.$refs['result'].focus();
      } else if (this.projectInfo.capital == "") {
        alert("申请资金不能为空");
        this.$refs['capital'].focus();
      } else {
        this.projectInfo.categoryid = this.getCid();
        var _this = this;
        this.$axios({
          url: 'http://localhost:8080/api/unit/applyProject',
          method: 'post',
          data: _this.projectInfo
        }).then((res) => {
          // console.log(res);
          if (res.data.code == 200) {
            alert(res.data.msg);
          } else {
            alert(res.data.msg);
          }
        })
      }
    },
    resetProjectInfo() {     //重置
      this.projectInfo.projectName = '';
      this.projectInfo.applicant = '';
      this.projectInfo.grade = '';
      this.projectInfo.education = '';
      this.projectInfo.status = '';
      this.projectInfo.future = '';
      this.projectInfo.analysis = '';
      this.projectInfo.way = '';
      this.projectInfo.result = '';
      this.projectInfo.capital = '';
    }
  }
}
</script>

<style scoped>
@import "@/assets/css/unit_andreas08(blue).css";
</style>
